﻿//=====================================================================================================
// LocalizationLibrary
// The Localization Library is a collection of reusable software components that provide 
// support for localization. This library enables you to localize WPF, Silverlight and WP7 applications.
// (http://localizationlibrary.codeplex.com)
//=====================================================================================================
// Author: Nicola Gallo (Website: www.nicola.gallo.name, Email: nicolagmt@hotmail.it) 
//=====================================================================================================

namespace LocalizationLibrary.Tests.Core.SystemExtensions
{
    //.NET References
    using System;
    using System.Text;
    using System.Collections.Generic;
    using System.Linq;
    using System.Reflection;

    //LocalizationLibrary References
    using LocalizationLibrary;
    
    //Microsoft References
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using LocalizationLibrary.Tests.Infrastructure;

    [TestClass]
    public class SystemTest
    {
        [ExpectedException(typeof(ArgumentException))]
        [TestMethod]
        public void Thrown_ArgumentException_If_Language_Is_Not_Valide()
        {
            "pippo".Localize(null);
        }

        [ExpectedException(typeof(ArgumentException))]
        [TestMethod]
        public void Thrown_ArgumentException_If_Language_Is_Not_Valide2()
        {
            "pippo".Localize(null, false);
        }

        [ExpectedException(typeof(ArgumentException))]
        [TestMethod]
        public void Thrown_ArgumentException_If_Language_Is_Not_Valide3()
        {
            "pippo".Localize(null, true);
        }

        [TestMethod]
        public void Localize() 
        {
            using (LocalizationLibraryContext llContext = new LocalizationLibraryContext(true))
            {
                //Resets current context.
                llContext.Reset();

                //Registers DeploymentPackA.
                {
                    Assembly assembly = typeof(DeployPackA.Tests.DeployPackAClass).Assembly;
                    LocalizationManager.RegisterAssembly(assembly);
                }

                DeployPackA.Tests.LocalizationModels.LocalizationModelA locModelA =
                    new DeployPackA.Tests.LocalizationModels.LocalizationModelA();
                LocalizationManager.RegisterLocalizationModel(locModelA);
                llContext.WaitForLocalization();

                String currentLanguage = LocalizationManager.CurrentLanguage.Code;
                llContext.Start((_context) =>
                {
                    llContext.SetValue(currentLanguage, "nameDPAKey".Localize("en"));
                    llContext.SetValue("it", "nameDPAKey".Localize("it"));
                    llContext.SetValue("fr", "nameDPAKey".Localize("fr", true));
                });
                llContext.Join();

                Assert.AreEqual(llContext.GetValue<String>(currentLanguage), "Name");
                Assert.AreEqual(llContext.GetValue<String>("it"), "Questo è il mio nome");
                Assert.AreEqual(llContext.GetValue<String>("fr"), "nameDPAKey[fr]");
            }
        }
    }
}